package com.sx.zongzhi.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.Spinner;
import android.widget.TextView;

import com.sx.zongzhi.BaseActivity;
import com.sx.zongzhi.R;
import com.sx.zongzhi.bean.BoxSearchBean;
import com.sx.zongzhi.utils.BaseUtil;
import com.sx.zongzhi.utils.MyRxBus;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 收件箱/发件箱查询
 */
public class InBoxSearchActivity extends BaseActivity {

    @BindView(R.id.ll_Sender)
    LinearLayout ll_Sender;
    @BindView(R.id.ll_MesType)
    LinearLayout ll_MesType;
    @BindView(R.id.et_Title)
    EditText etTitle;
    @BindView(R.id.et_Sender)
    EditText etSender;
    @BindView(R.id.sp_MesType)
    Spinner spMesType;
    @BindView(R.id.tv_StartTime)
    TextView tvStartTime;
    @BindView(R.id.tv_EndTime)
    TextView tvEndTime;

    /**
     * 收件还是发件 0:收件 1：发件
     */
    private int IN_OR_SEND;

    private String type = "0";

    @Override
    public void setUI(Bundle savedInstanceState) {
        setContentView(R.layout.activity_in_box_search);
        setTitleName("收件消息查询");
        setTitleRight(R.string.search);
        IN_OR_SEND = getIntent().getIntExtra("MAIL_TYPE", 0);
        ButterKnife.bind(this);
        initViews();
    }

    private void initViews() {
        if (IN_OR_SEND != 0) {
            ll_Sender.setVisibility(View.GONE);
            ll_MesType.setVisibility(View.GONE);
        }
        spMesType.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                type = position + "";
            }
            @Override
            public void onNothingSelected(AdapterView<?> parent) {
            }
        });
    }

    @OnClick({R.id.tv_right,R.id.tv_StartTime,R.id.tv_EndTime})
    public void OnClick(View view) {
        switch (view.getId()) {
            case R.id.tv_right:
                BoxSearchBean bean = new BoxSearchBean();
                bean.mailType = IN_OR_SEND;
                bean.searchTitle = etTitle.getText().toString().trim();
                bean.searchSenderName = etSender.getText().toString().trim();
                bean.searchMessageType = type ;
                bean.searchTimeStart = tvStartTime.getText().toString().trim();
                bean.searchTimeEnd = tvEndTime.getText().toString().trim();
                MyRxBus.get().post(bean);
                BaseUtil.hintKb(this);
                finish();
                break;
            case R.id.tv_StartTime:
                BaseUtil.createDataPop(this,tvStartTime);
                break;
            case R.id.tv_EndTime:
                BaseUtil.createDataPop(this,tvEndTime);
                break;
        }
    }

}
